{layout name="layout" /}

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i>
	<a href="{:url('index/index')}"> 首页</a>
	<span class="c-gray en">&gt;</span>
	<a href="{:url('category/index')}">栏目管理</a>
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
		href="javascript:location.replace(location.href);" title="刷新">
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>

<div class="Hui-article">
	<article class="cl pd-20">
		<div class="cl pd-5 bg-1 bk-gray">
			<span class="l">
				<a href="javascript:;" onclick="del_all()" class="btn btn-danger radius">
					<i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
				<a class="btn btn-primary radius" href="{:url('category/info')}">
					<i class="Hui-iconfont">&#xe600;</i> 添加栏目</a>
			</span>
			<!-- <span class="r">共有数据：<strong>54</strong> 条</span>  -->
		</div>
		<div class="mt-10" style="min-width:920px;">
			<table class="table table-border table-bordered table-hover table-bg">
				<thead>
					<tr class="text-c">
						<th width="25px">
							<input type="checkbox" value="" name="">
						</th>
						<th width="80px">ID</th>
						<th width="80px">父ID</th>
						<th>栏目名称</th>
						<th width="100px">类型</th>
						<th width="100px">排序</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					{foreach $data as $value}
					<tr class="text-c">
						<td>
							<input type="checkbox" value="{$value.id}" name="checkbox[]">
						</td>
						<td>{$value.id}</td>
						<td>{$value.pid}</td>
						<td class="text-l">{if $val.value==2}{$value.name}{else/}<a
								href="{if $value.type==1}{$value.url}{else/}/article/list.html?cid={$value.id}{/if}"
								target="_blank">{$value.name}</a>{/if}
						</td>
						<td>{$types[$value.type]}</td>
						<td>{$value.sort}</td>
						<td class="td-manage">
							<a title="编辑" href="{:url('category/info?id='.$value.id)}" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							<a title="删除" href="javascript:;" onclick="del(this,'{$value.id}')" class="ml-5"
								style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						</td>
					</tr>
					{notempty name="value.child"} {foreach $value.child as $val}
					<tr class="text-c">
						<td>
							<input type="checkbox" value="{$val.id}" name="checkbox[]">
						</td>
						<td>{$val.id}</td>
						<td>{$val.pid}</td>
						<td class="text-l">{if $val.type==2}{$val.name}{else/}<a
								href="{if $val.type==1}{$val.url}{else/}/article/list.html?cid={$val.id}{/if}"
								target="_blank">{$val.name}</a>{/if}
						</td>
						<td>{$types[$val.type]}</td>
						<td>{$val.sort}</td>
						<td class="td-manage">
							<a title="编辑" href="{:url('category/info?id='.$val.id)}" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							<a title="删除" href="javascript:;" onclick="del(this,'{$val.id}')" class="ml-5"
								style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						</td>
					</tr>
					{notempty name="val.child"} {foreach $val.child as $vo}
					<tr class="text-c">
						<td>
							<input type="checkbox" value="{$vo.id}" name="checkbox[]">
						</td>
						<td>{$vo.id}</td>
						<td>{$vo.pid}</td>
						<td class="text-r"><a
								href="{if $vo.type==1}{$vo.url}{else/}/article/list.html?cid={$vo.id}{/if}"
								target="_blank">{$vo.name}</a></td>
						<td>{$types[$vo.type]}</td>
						<td>{$vo.sort}</td>
						<td class="td-manage">
							<a title="编辑" href="{:url('category/info?id='.$vo.id)}" style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6df;</i>
							</a>
							<a title="删除" href="javascript:;" onclick="del(this,'{$vo.id}')" class="ml-5"
								style="text-decoration:none">
								<i class="Hui-iconfont">&#xe6e2;</i>
							</a>
						</td>
					</tr>
					{/foreach} {/notempty}{/foreach} {/notempty} {/foreach}
				</tbody>
			</table>
		</div>
	</article>
</div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
	function del(obj, id) {
		layer.confirm('确认要删除吗？', function (index) {
			$.post('delete', {
				'id': id
			}, function (data) {
				if (data.code == 1) {
					console.log($(obj));
					$(obj).parents("tr").remove();
					layer.msg(data.msg, {
						icon: 1,
						time: 1000
					});
				} else {
					layer.msg(data.msg, {
						icon: 5,
						time: 2000
					});
					return false;
				}
			}, 'json');
		});
	}

	/*
	* 批量删除条目
	*/
	function del_all() {
		var checkbox = $('.text-c input[name="checkbox[]"]');
		var ids = new Array();
		checkbox.each(function (x) {
			if (this.checked)
				ids.push(this.value);
		})
		// console.log(ids);
		layer.confirm('确认要删除吗？', function (index) {
			$.post('delete', {
				'id': ids
			}, function (data) {
				if (data.code == 1) {
					layer.msg(data.msg, {
						icon: 1,
						time: 1000
					});
					checkbox.each(function (x) {
						if (this.checked)
							$(this).parents("tr").remove();
					})
				} else {
					layer.msg(data.msg, {
						icon: 5,
						time: 1000
					});
				}
			}, 'json')
		});
	}
</script>
<!--请在上方写此页面业务相关的脚本-->